import { toArray } from '../../utils';
export function chooseMedia(options) {
    const { count = 9, mediaType = 'image', sourceType = ['album', 'camera'], maxDuration = 10, sizeType = ['original', 'compressed'], camera = 'back', success, fail, complete, } = options;
    if (mediaType === 'image') {
        return uni.chooseImage({
            count,
            sizeType,
            sourceType,
            success(res) {
                success?.({
                    type: 'image',
                    tempFiles: toArray(res.tempFiles).map((file) => {
                        return {
                            tempFilePath: file.path,
                            size: file.size,
                            duration: 0,
                            height: 0,
                            width: 0,
                            name: file.name || '',
                            fileType: 'image',
                        };
                    }),
                });
            },
            fail,
            complete,
        });
    }
    else {
        return uni.chooseVideo({
            sourceType,
            compressed: sizeType.includes('compressed'),
            maxDuration,
            camera,
            success(res) {
                success?.({
                    type: 'video',
                    tempFiles: [
                        {
                            tempFilePath: res.tempFilePath,
                            size: res.size,
                            duration: res.duration,
                            height: res.height,
                            width: res.width,
                            name: res.name || '',
                            fileType: 'video',
                        },
                    ],
                });
            },
            fail,
            complete,
        });
    }
}
